package com.mlx.permission.inter;

import com.mlx.permission.entity.Permission;
import com.mlx.permission.util.PermissionUtil;

import java.util.Collection;

/**
 * 验证器：继承容器与收集器并提供验证权限的方法
 * @param <P> 收集器泛型参数
 * @param <C> 容器泛型参数
 */
public interface Validator<P extends Permission, C> extends Collector<P>, Container<C> {

    /**
     * 用于判断当前实体是否是开放实体
     *     先判断内置开放实体，再判断普通实体
     * @return 布尔值
     */
    default boolean isOpenEntity(){
        String currentEntity = getCurrentEntity();
        Collection<String> builtInOpenEntity = getBuiltInOpenEntityCollection();
        if (PermissionUtil.isNotEmpty(builtInOpenEntity) && builtInOpenEntity.contains(currentEntity)){
            return true;
        }

        Collection<String> openEntity = getOpenEntityCollection();
        return PermissionUtil.isNotEmpty(openEntity) && openEntity.contains(currentEntity);
    }

}
